<template>
  <div>
    <h1>添加学生</h1>
    <table>
      <tr>
        <td>姓名: <input v-model="data.name" type="text" /></td>
        <td>账号: <input v-model="data.account" type="text" /></td>
        <td>密码: <input v-model="data.password" type="text" /></td>
        <td>电话: <input v-model="data.tel" type="text" /></td>
        <td>生日: <input v-model="data.birthday" type="text" /></td>
      </tr>
      <tr>
        <td>
          状态： 正常<input v-model="data.role" type="radio" value="1" />
          休学<input v-model="data.role" type="radio" value="2" /> 退学<input
            v-model="data.role"
            type="radio"
            value="3"
          />
        </td>
      </tr>
      <tr>
        <td>
          <el-button type="primary" @click="editStudent">添加学生</el-button>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: 'editStudent',
  data () {
    return {
      data: {
        id: '',
        name: '',
        account: '',
        password: '',
        tel: '',
        avatar: '',
        birthday: '',
        status: '',
        role: '',
        class_id: ''
      }
    }
  },
  created () {
    this.getStudent()
  },
  methods: {
    async getStudent () {
      // 获取学生表id
      console.log(this.$route.query)
      // this.id = this.$route.query.id;
      const { data: res } = await this.$http({
        method: 'get',
        url: 'http://localhost/detailStudent.php?id=' + this.$route.query.id
      })
      if (res.code !== 0) return
      this.data = res.data[0]
    },
    // 编辑学生
    editStudent () {
      this.$http({
        method: 'post',
        url: 'http://localhost/editStudent.php',
        data: this.data
      }).then((res) => {
        const data = res.data
        if (data.code === 0) {
          alert('编辑成功')
        } else {
          alert('编辑出错')
        }
      })
    },

    cancel () {
      this.$router.push('/student')
    }
  }
}
</script>

<style></style>
